package com.itheima.demo;

import com.alibaba.druid.pool.DruidDataSource;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.SQLException;

public class DemoDruid {
    public static void main(String[] args) throws SQLException {
        ApplicationContext ac = new ClassPathXmlApplicationContext("spring.xml");
        DataSource dataSource = ac.getBean("dataSource", DataSource.class);
        System.out.println(dataSource.getConnection());
    }

    public static void main1(String[] args) throws SQLException {
        //1. 创建数据库连接池对象
        DruidDataSource source = new DruidDataSource();
        //2. 配置连接数据库的四大基本特征
        source.setDriverClassName("com.mysql.jdbc.Driver");
        source.setUrl("jdbc:mysql://192.168.23.129:3306/db4");
        source.setUsername("root");
        source.setPassword("root");
        //3. 获取连接对象
        Connection con = source.getConnection();
        System.out.println(con);
    }
}
